﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using TrangTrai.Data.DAO;
using DevExpress.XtraCharts;

namespace Trangtrai.report
{
    public partial class EnvReport : System.Web.UI.Page
    {
       static ReportDAO reportDao = new ReportDAO();
       static SeasonInfo[] arrSeasons = null;
       static AoInfo[] arrAoInfo = null;
       static GroupManagementDAO dao = new GroupManagementDAO();
       TrangTrai.Data.DAO.EnvReport[] envReport;
       static int aoId;
       static int seasonId;
       static DateTime _toDate;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                arrSeasons = dao.getSeasonList();
                arrAoInfo = dao.getActiveAoList();
                cbAoCode.DataSource = arrAoInfo;
                cbAoCode.DataBind();
                cbSeason.DataSource = arrSeasons;
                cbSeason.DataBind();
               
            }
            else {
                aoId = (int)cbAoCode.Value;
                seasonId = (int)cbSeason.Value;
                _toDate = (DateTime)toDate.Value;
                envReport = reportDao.getEnReport(aoId, seasonId, _toDate);
                grid.DataSource = envReport;
                grid.DataBind();
            }
   
        }

        protected void btnsearch_Click(object sender, EventArgs e)
        {
            aoId= (int)cbAoCode.Value;
            seasonId = (int)cbSeason.Value;
            _toDate = (DateTime)toDate.Value;
            envReport = reportDao.getEnReport(aoId, seasonId, _toDate);
            grid.DataSource = envReport;
            grid.DataBind();
            // do tang truong chart
            DoTangTruongReport[] doTangReport= reportDao.getDoTangTruong(aoId, seasonId, _toDate);
             Series actualValueSer= rpDoTangTruogn.Series["actual"];
             Series standardValueSer = rpDoTangTruogn.Series["standard"];
             Series sampleValueSer = rpDoTangTruogn.Series["sample"];
            foreach(DoTangTruongReport item  in doTangReport){
                  actualValueSer.Points.Add(new SeriesPoint(item.tomAge,new double[]{item.actualValue}));
                  standardValueSer.Points.Add(new SeriesPoint(item.tomAge, new double[] { item.standardValue }));
                  sampleValueSer.Points.Add(new SeriesPoint(item.tomAge, new double[] { item.sampleValue }));

            }
            // bieu do so sanh do kiem
            DoKiemReport[] doKiemReport = reportDao.getDoKiemReport(aoId, seasonId, _toDate);
            Series actualValueSer1 = rpDoKiem.Series["actual"];
            Series standardValueSer1 = rpDoKiem.Series["standard"];
            foreach (DoKiemReport item in doKiemReport)
            {
                actualValueSer1.Points.Add(new SeriesPoint(item.tomAge, new double[] { item.actualValue }));
                standardValueSer1.Points.Add(new SeriesPoint(item.tomAge, new double[] { item.standardValue }));
               

            }
            // bieu do so sanh do kiem
            DoManReport[] doManReport = reportDao.getDoManReport(aoId, seasonId, _toDate);
            Series actualValueSer2 = rpDoMan.Series["actual"];
            Series standardValueSer2 = rpDoMan.Series["standard"];
            foreach (DoManReport item in doManReport)
            {
                actualValueSer2.Points.Add(new SeriesPoint(item.tomAge, new double[] { item.actualValue }));
                standardValueSer2.Points.Add(new SeriesPoint(item.tomAge, new double[] { item.standardValue }));
            }

            // bieu do so sanh do kiem
            DoTrongReport[] doTrongReport = reportDao.getDoTrongReport(aoId, seasonId, _toDate);
            Series actualValueSer3 = rpDoTrong.Series["actual"];
            Series standardValueSer3 = rpDoTrong.Series["standard"];
            foreach (DoTrongReport item in doTrongReport)
            {
                actualValueSer3.Points.Add(new SeriesPoint(item.tomAge, new double[] { item.actualValue }));
                standardValueSer3.Points.Add(new SeriesPoint(item.tomAge, new double[] { item.standardValue }));
            }

            // bieu do so sanh do kiem
            DoOxiHoaReport[] doOxiHoaReport = reportDao.getDoOxiHoaReport(aoId, seasonId, _toDate);
            Series bodValue = rpBod.Series["bodValue"];
            Series codValue = rpBod.Series["codValue"];
            Series doValue = rpBod.Series["doValue"];
            foreach (DoOxiHoaReport item in doOxiHoaReport)
            {
                bodValue.Points.Add(new SeriesPoint(item.tomAge, new double[] { item.bodValue }));
                codValue.Points.Add(new SeriesPoint(item.tomAge, new double[] { item.codValue }));
                codValue.Points.Add(new SeriesPoint(item.tomAge, new double[] { item.doValue }));
            }
            
        }
    }
}
